﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Aim2.Weapon.Projectile;

namespace Aim2 {
    class Asteroid : Projectile {
        static Texture2D spriteTexture;

        float rotationWise;

        public Asteroid(Vector2 Position, IObjectContainer owner, Side side = Aim2.Side.Ennemy) {
            this.direction = new Vector2((float) Game.Random.NextDouble(), (float) Game.Random.NextDouble());
            if (Game.Random.Next(2) == 1)
                this.direction.X = -1 * this.direction.X;

            this.side = side;

            Scale = (float) Game.Random.NextDouble() * Game.Random.Next(0, 6);
            Depth = 1f;
            frames = 30;
            framesPerSec = 18;
            speed = 10f;
            Rotation = Game.Random.Next(0, 7);
            rotationWise = (float) Game.Random.NextDouble() / 10f;
            if (Game.Random.Next(0, 2) == 0)
                rotationWise *= -1;
            this.Position = Position;

            Health = Scale * 1.5f;
            CollisionDamage = Scale;
            this.owner = owner;
            animatedSprite = new AnimatedSprite(this, frames, framesPerSec);
        }

        public override Side Side() {
            return side;
        }

        public override void Load(ContentManager Content, Viewport viewport) {
            spriteTexture = Content.Load<Texture2D>("Textures/5x6_asteroid");
            spriteTexture.Name = "Textures/5x6_asteroid";

            layout = spriteTexture.Name.GetLayout();
            height = spriteTexture.Height;
            width = spriteTexture.Width;

        }

        public override void Update(float elapsed) {
            Position = Position + direction * speed;
            Rotation += rotationWise;

            base.Update(elapsed);
        }

        public override void Draw(SpriteBatch spriteBatch) {
            base.Draw(spriteBatch);
            animatedSprite.DrawFrame(spriteBatch, Position, spriteTexture);
        }
    }
}
